Fix HTML email sending

Andrew Cantino 11 years ago
parent
commit
c2990c7c4b

+ 1 - 1
app/views/system_mailer/send_message.html.erb

@@ -12,7 +12,7 @@
12 12
         <div><%= group[:title] %></div>
13 13
         <% group[:entries].each do |entry| %>
14 14
           <div style='margin-left: 10px;'>
15
-            <%= group[:entry] %>
15
+            <%= entry %>
16 16
           </div>
17 17
         <% end %>
18 18
       </div>

+ 26 - 1
spec/models/agents/digest_email_agent_spec.rb

@@ -11,6 +11,10 @@ describe Agents::DigestEmailAgent do
11 11
     @checker.save!
12 12
   end
13 13
 
14
+  after do
15
+    ActionMailer::Base.deliveries = []
16
+  end
17
+
14 18
   describe "#receive" do
15 19
     it "queues any payloads it receives" do
16 20
       event1 = Event.new
@@ -43,7 +47,28 @@ describe Agents::DigestEmailAgent do
43 47
       ActionMailer::Base.deliveries.last.to.should == ["bob@example.com"]
44 48
       ActionMailer::Base.deliveries.last.subject.should == "something interesting"
45 49
       get_message_part(ActionMailer::Base.deliveries.last, /plain/).strip.should == "Something you should know about\n\nFoo\n  bar: 2\n  url: http://google.com\n\nhi\n  woah: there\n\nEvent\n  test: 2"
46
-      @checker.reload.memory[:queue].should == []
50
+      @checker.reload.memory[:queue].should be_empty
51
+    end
52
+
53
+    it "can receive complex events and send them on" do
54
+      stub_request(:any, /wunderground/).to_return(:body => File.read(Rails.root.join("spec/data_fixtures/weather.json")), :status => 200)
55
+      stub.any_instance_of(Agents::WeatherAgent).is_tomorrow?(anything) { true }
56
+      @checker.sources << agents(:bob_weather_agent)
57
+
58
+      Agent.async_check(agents(:bob_weather_agent).id)
59
+
60
+      Agent.receive!
61
+      @checker.reload.memory[:queue].should_not be_empty
62
+
63
+      Agents::DigestEmailAgent.async_check(@checker.id)
64
+
65
+      plain_email_text = get_message_part(ActionMailer::Base.deliveries.last, /plain/).strip
66
+      html_email_text = get_message_part(ActionMailer::Base.deliveries.last, /html/).strip
67
+
68
+      plain_email_text.should =~ /avehumidity/
69
+      html_email_text.should =~ /avehumidity/
70
+
71
+      @checker.reload.memory[:queue].should be_empty
47 72
     end
48 73
   end
49 74
 end